from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-28 14:02:08.872670
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 28, Apr, 2022
Time: 14:02:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0909
Nobs: 640.000 HQIC: -49.4748
Log likelihood: 7826.78 FPE: 2.55633e-22
AIC: -49.7183 Det(Omega_mle): 2.22339e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.328123 0.062148 5.280 0.000
L1.Burgenland 0.105336 0.039411 2.673 0.008
L1.Kärnten -0.110460 0.020662 -5.346 0.000
L1.Niederösterreich 0.197599 0.082367 2.399 0.016
L1.Oberösterreich 0.118071 0.081247 1.453 0.146
L1.Salzburg 0.258632 0.041872 6.177 0.000
L1.Steiermark 0.043300 0.055064 0.786 0.432
L1.Tirol 0.105788 0.044433 2.381 0.017
L1.Vorarlberg -0.064841 0.039319 -1.649 0.099
L1.Wien 0.024473 0.072046 0.340 0.734
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050659 0.132861 0.381 0.703
L1.Burgenland -0.033717 0.084254 -0.400 0.689
L1.Kärnten 0.040555 0.044171 0.918 0.359
L1.Niederösterreich -0.192479 0.176085 -1.093 0.274
L1.Oberösterreich 0.447997 0.173691 2.579 0.010
L1.Salzburg 0.285748 0.089516 3.192 0.001
L1.Steiermark 0.106661 0.117717 0.906 0.365
L1.Tirol 0.313126 0.094990 3.296 0.001
L1.Vorarlberg 0.024394 0.084057 0.290 0.772
L1.Wien -0.034515 0.154023 -0.224 0.823
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189108 0.031837 5.940 0.000
L1.Burgenland 0.090552 0.020189 4.485 0.000
L1.Kärnten -0.007932 0.010585 -0.749 0.454
L1.Niederösterreich 0.248724 0.042194 5.895 0.000
L1.Oberösterreich 0.157161 0.041620 3.776 0.000
L1.Salzburg 0.040606 0.021450 1.893 0.058
L1.Steiermark 0.025654 0.028208 0.909 0.363
L1.Tirol 0.086914 0.022762 3.818 0.000
L1.Vorarlberg 0.054279 0.020142 2.695 0.007
L1.Wien 0.116356 0.036907 3.153 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110374 0.031988 3.450 0.001
L1.Burgenland 0.045520 0.020285 2.244 0.025
L1.Kärnten -0.014292 0.010635 -1.344 0.179
L1.Niederösterreich 0.179885 0.042395 4.243 0.000
L1.Oberösterreich 0.327488 0.041818 7.831 0.000
L1.Salzburg 0.101659 0.021552 4.717 0.000
L1.Steiermark 0.110896 0.028342 3.913 0.000
L1.Tirol 0.097742 0.022870 4.274 0.000
L1.Vorarlberg 0.060107 0.020238 2.970 0.003
L1.Wien -0.020206 0.037083 -0.545 0.586
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112507 0.059584 1.888 0.059
L1.Burgenland -0.043005 0.037785 -1.138 0.255
L1.Kärnten -0.046224 0.019810 -2.333 0.020
L1.Niederösterreich 0.144343 0.078969 1.828 0.068
L1.Oberösterreich 0.156569 0.077895 2.010 0.044
L1.Salzburg 0.283823 0.040145 7.070 0.000
L1.Steiermark 0.056307 0.052792 1.067 0.286
L1.Tirol 0.165895 0.042600 3.894 0.000
L1.Vorarlberg 0.097672 0.037697 2.591 0.010
L1.Wien 0.074255 0.069074 1.075 0.282
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058569 0.046899 1.249 0.212
L1.Burgenland 0.030299 0.029741 1.019 0.308
L1.Kärnten 0.051538 0.015592 3.305 0.001
L1.Niederösterreich 0.205222 0.062156 3.302 0.001
L1.Oberösterreich 0.322931 0.061311 5.267 0.000
L1.Salzburg 0.038281 0.031598 1.211 0.226
L1.Steiermark 0.007496 0.041553 0.180 0.857
L1.Tirol 0.130282 0.033531 3.885 0.000
L1.Vorarlberg 0.064628 0.029671 2.178 0.029
L1.Wien 0.091570 0.054369 1.684 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172052 0.056299 3.056 0.002
L1.Burgenland 0.005679 0.035702 0.159 0.874
L1.Kärnten -0.065092 0.018717 -3.478 0.001
L1.Niederösterreich -0.097757 0.074615 -1.310 0.190
L1.Oberösterreich 0.204007 0.073600 2.772 0.006
L1.Salzburg 0.055170 0.037932 1.454 0.146
L1.Steiermark 0.239961 0.049881 4.811 0.000
L1.Tirol 0.501469 0.040251 12.458 0.000
L1.Vorarlberg 0.061993 0.035618 1.740 0.082
L1.Wien -0.075119 0.065266 -1.151 0.250
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.144468 0.062433 2.314 0.021
L1.Burgenland 0.004490 0.039592 0.113 0.910
L1.Kärnten 0.060606 0.020757 2.920 0.004
L1.Niederösterreich 0.182975 0.082744 2.211 0.027
L1.Oberösterreich -0.062490 0.081619 -0.766 0.444
L1.Salzburg 0.208187 0.042064 4.949 0.000
L1.Steiermark 0.135102 0.055316 2.442 0.015
L1.Tirol 0.068229 0.044637 1.529 0.126
L1.Vorarlberg 0.146969 0.039499 3.721 0.000
L1.Wien 0.113259 0.072377 1.565 0.118
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.376758 0.036759 10.249 0.000
L1.Burgenland -0.001007 0.023311 -0.043 0.966
L1.Kärnten -0.021826 0.012221 -1.786 0.074
L1.Niederösterreich 0.211440 0.048718 4.340 0.000
L1.Oberösterreich 0.226042 0.048056 4.704 0.000
L1.Salzburg 0.038895 0.024767 1.570 0.116
L1.Steiermark -0.013564 0.032569 -0.416 0.677
L1.Tirol 0.094924 0.026281 3.612 0.000
L1.Vorarlberg 0.053111 0.023256 2.284 0.022
L1.Wien 0.037354 0.042614 0.877 0.381
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036599 0.113898 0.174121 0.141507 0.102985 0.085833 0.038709 0.210248
Kärnten 0.036599 1.000000 -0.021238 0.134160 0.052604 0.089972 0.441925 -0.061135 0.092590
Niederösterreich 0.113898 -0.021238 1.000000 0.323031 0.130349 0.284156 0.075561 0.162773 0.296831
Oberösterreich 0.174121 0.134160 0.323031 1.000000 0.222496 0.310012 0.168641 0.150017 0.249445
Salzburg 0.141507 0.052604 0.130349 0.222496 1.000000 0.132648 0.097302 0.113233 0.130464
Steiermark 0.102985 0.089972 0.284156 0.310012 0.132648 1.000000 0.139826 0.120946 0.049166
Tirol 0.085833 0.441925 0.075561 0.168641 0.097302 0.139826 1.000000 0.069062 0.149765
Vorarlberg 0.038709 -0.061135 0.162773 0.150017 0.113233 0.120946 0.069062 1.000000 0.006778
Wien 0.210248 0.092590 0.296831 0.249445 0.130464 0.049166 0.149765 0.006778 1.000000